package allod.gui

import net.miginfocom.swing.MigLayout
import swing.{Component, LayoutContainer, Panel}
import javax.swing.{JComponent, JPanel}

/**
 * Created by IntelliJ IDEA.
 * User: allod
 * Date: 13 лист 2009
 * Time: 21:27:52
 */

class MigPanel(layoutConstraints: String, colConstraints: String, rowConstraints: String)
        extends Panel with LayoutContainer {
  type Constraints = String

  def this(layoutConstraints: String, colConstraints: String) =
    this (layoutConstraints, colConstraints, "")

  def this(layoutConstraints: String) =
    this (layoutConstraints, "", "")

  def this() = this ("", "", "")

  override lazy val peer = new JPanel(new MigLayout(layoutConstraints, colConstraints, rowConstraints))

  def layoutManager = peer.getLayout.asInstanceOf[MigLayout]

  def constraintsFor(comp: Component) =
    layoutManager.getComponentConstraints(comp.peer).asInstanceOf[String]

  def constraintsFor_=(comp: Component)(constraints: Constraints) {
    layoutManager.setComponentConstraints(comp.peer, constraints)
  }

  protected def areValid(c: Constraints): (Boolean, String) = (true, "")

  def add(c: Component, const: String) {
    peer.add(c.peer, const)
  }

  def add(c: JComponent, const: String) {
    peer.add(c, const)
  }

  def add(c: Component) {
    peer.add(c.peer)
  }

  def add(c: JComponent) {
    peer.add(c)
  }

  def +=(c: Component) {
    add(c)
  }

  def +=(c: JComponent) {
    add(c)
  }
}